package cn.ds.assets.module.assets.controller.admin.dataQualityRuleSetValue;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.ds.assets.framework.common.pojo.PageResult;
import cn.ds.assets.framework.common.pojo.CommonResult;
import static cn.ds.assets.framework.common.pojo.CommonResult.success;

import cn.ds.assets.framework.excel.core.util.ExcelUtils;

import cn.ds.assets.framework.operatelog.core.annotations.OperateLog;
import static cn.ds.assets.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.ds.assets.module.assets.controller.admin.dataQualityRuleSetValue.vo.*;
import cn.ds.assets.module.assets.dal.dataobject.dataQualityRuleSetValue.BaseDataQualityRuleSetValueDO;
import cn.ds.assets.module.assets.convert.dataQualityRuleSetValue.BaseDataQualityRuleSetValueConvert;
import cn.ds.assets.module.assets.service.dataQualityRuleSetValue.BaseDataQualityRuleSetValueService;

//@Tag(name = "管理后台 - 数据质量规则设置值")
//@RestController
//@RequestMapping("/assets/base-data-quality-rule-set-value")
@Validated
public class BaseDataQualityRuleSetValueController {

    @Resource
    private BaseDataQualityRuleSetValueService baseDataQualityRuleSetValueService;

    @PostMapping("/create")
    @Operation(summary = "创建数据质量规则设置值")
    @PreAuthorize("@ss.hasPermission('assets:base-data-quality-rule-set-value:create')")
    public CommonResult<Long> createBaseDataQualityRuleSetValue(@Valid @RequestBody BaseDataQualityRuleSetValueCreateReqVO createReqVO) {
        return success(baseDataQualityRuleSetValueService.createBaseDataQualityRuleSetValue(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新数据质量规则设置值")
    @PreAuthorize("@ss.hasPermission('assets:base-data-quality-rule-set-value:update')")
    public CommonResult<Boolean> updateBaseDataQualityRuleSetValue(@Valid @RequestBody BaseDataQualityRuleSetValueUpdateReqVO updateReqVO) {
        baseDataQualityRuleSetValueService.updateBaseDataQualityRuleSetValue(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除数据质量规则设置值")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('assets:base-data-quality-rule-set-value:delete')")
    public CommonResult<Boolean> deleteBaseDataQualityRuleSetValue(@RequestParam("id") Long id) {
        baseDataQualityRuleSetValueService.deleteBaseDataQualityRuleSetValue(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得数据质量规则设置值")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('assets:base-data-quality-rule-set-value:query')")
    public CommonResult<BaseDataQualityRuleSetValueRespVO> getBaseDataQualityRuleSetValue(@RequestParam("id") Long id) {
        BaseDataQualityRuleSetValueDO baseDataQualityRuleSetValue = baseDataQualityRuleSetValueService.getBaseDataQualityRuleSetValue(id);
        return success(BaseDataQualityRuleSetValueConvert.INSTANCE.convert(baseDataQualityRuleSetValue));
    }

    @GetMapping("/list")
    @Operation(summary = "获得数据质量规则设置值列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('assets:base-data-quality-rule-set-value:query')")
    public CommonResult<List<BaseDataQualityRuleSetValueRespVO>> getBaseDataQualityRuleSetValueList(@RequestParam("ids") Collection<Long> ids) {
        List<BaseDataQualityRuleSetValueDO> list = baseDataQualityRuleSetValueService.getBaseDataQualityRuleSetValueList(ids);
        return success(BaseDataQualityRuleSetValueConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得数据质量规则设置值分页")
    @PreAuthorize("@ss.hasPermission('assets:base-data-quality-rule-set-value:query')")
    public CommonResult<PageResult<BaseDataQualityRuleSetValueRespVO>> getBaseDataQualityRuleSetValuePage(@Valid BaseDataQualityRuleSetValuePageReqVO pageVO) {
        PageResult<BaseDataQualityRuleSetValueDO> pageResult = baseDataQualityRuleSetValueService.getBaseDataQualityRuleSetValuePage(pageVO);
        return success(BaseDataQualityRuleSetValueConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出数据质量规则设置值 Excel")
    @PreAuthorize("@ss.hasPermission('assets:base-data-quality-rule-set-value:export')")
    @OperateLog(type = EXPORT)
    public void exportBaseDataQualityRuleSetValueExcel(@Valid BaseDataQualityRuleSetValueExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<BaseDataQualityRuleSetValueDO> list = baseDataQualityRuleSetValueService.getBaseDataQualityRuleSetValueList(exportReqVO);
        // 导出 Excel
        List<BaseDataQualityRuleSetValueExcelVO> datas = BaseDataQualityRuleSetValueConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "数据质量规则设置值.xls", "数据", BaseDataQualityRuleSetValueExcelVO.class, datas);
    }

}
